﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rappelz.GameServer
{
    public class StateDamage
    {
        public StateDamage(uint _caster, Elemental.Type _type, int _base_effect_id, int _code, ushort _level, int _damage_hp, int _damage_mp, bool _final, ushort _uid)
        {
            this.caster = _caster;
            this.elemental_type = _type;
            this.base_effect_id = _base_effect_id;
            this.code = _code;
            this.level = _level;
            this.damage_hp = _damage_hp;
            this.damage_mp = _damage_mp;
            this.final = _final;
            this.uid = _uid;
        }

        public uint caster;                         // 0x0
        public Elemental.Type elemental_type;       // 0x4
        public int base_effect_id;                  // 0x8
        public int code;                            // 0xC
        public ushort level;                        // 0x10
        public int damage_hp;                       // 0x14
        public int damage_mp;                       // 0x18
        public bool final;                          // 0x1C
        public ushort uid;                          // 0x1E
    }


    public class State
    {
        public enum StateCode : int
        {
            None = 0,
            IncItemChance = 1020,
            IncBlockChance = 1021,
            HuntingCreatureCard = 2051,
            StaminaSave = 4003,
            SuperSave = 4102,
            HavocBurst = 4501,
            Frenzy = 4503,
            AddEnergy = 4504,
            BlessingOfGoddess = 4510,
            NemesisForAuto = 5997,
            Nemesis = 5999,
            Sleep = 6005,
            Stun = 6006,
            Hold = 6007,
            Fear = 6008,
            Frozen = 6009,
            StoneCurse = 6012,
            Mute = 6013,
            Hide = 6016,
            StoneCurseMortal = 6019,
            FallFromSummon = 9001,
            GaiaMembership = 9004,
            PCBangMembership = 9005,
            PCBangPremiumMembership = 9006,
            LunaChip = 9903,
            SummonGrowingCrackerWithoutPenalty = 9923,
            SummonGrowingCrackerWithPenalty = 9924,
            BurningStyle = 12671,
            AgileStyle = 12672,
            DuskStyle = 12673,
            SquallOfArrow = 12678,
            FrozenSnare = 13003,
            EarthRestriction = 13023,
            Nightmare = 13601,
            PassDamage = 14012,
            PetShovelingRewardIncMoveSpeed = 15000,
            PetShovelingRewardDecMoveSpeed = 15001,
            PetShovelingRewardIncStrInt = 15002,
            PetShovelingRewardDecStrInt = 15003,
            PetShovelingRewardIncAgiDex = 15004,
            PetShovelingRewardDexAgiDex = 15005,
            PetShovelingRewardIncVit = 15006,
            PetShovelingRewardDecVit = 15007,
            Seal = 999990,
            ShineWall = 999991,
            LightningForceCongestion = 163420,
            FusionWithSummon = 164001,
            SummonForm = 164002,
            ProtectingForceOfBeginning = 201085,
            TraceOfFugitive = 201084,
            MoveSpeedSlowdown = 313205,
        }

        public enum StateType : int
        {
            Normal = 0,
            Duplicate = 1,
            Dependence = 2,
        }


// VTable         :   , Type:  *
// Enum           :   StateGroup, Type: int
// Data           :     constant 0x0, Constant, Type: int, GROUP_NONE
// Data           :     constant 0x65, Constant, Type: int, GROUP_PHYSICAL_BOMB
// Data           :     constant 0x66, Constant, Type: int, GROUP_MAGICAL_BOMB
// Data           :     constant 0xC9, Constant, Type: int, GROUP_ASSASSIN
// Data           :     constant 0x12D, Constant, Type: int, GROUP_RIDING
// Data           :     constant 0x191, Constant, Type: int, GROUP_MAGIC
// Data           :     constant 0x192, Constant, Type: int, GROUP_SKILL
// Data           :     constant 0x193, Constant, Type: int, GROUP_POISON
// Data           :     constant 0x194, Constant, Type: int, GROUP_CURSE
// Data           :     constant 0x195, Constant, Type: int, GROUP_DISEASE
// Data           :     constant 0x196, Constant, Type: int, GROUP_WOUND
// Enum           :   StateBaseEffect, Type: int
// Data           :     constant 0x0, Constant, Type: int, EF_NONE
// Data           :     constant 0x1, Constant, Type: int, EF_PHYSICAL_STATE_DAMAGE
// Data           :     constant 0x2, Constant, Type: int, EF_PHYSICAL_IGNORE_DEFENCE_STATE_DAMAGE
// Data           :     constant 0x3, Constant, Type: int, EF_MAGICAL_STATE_DAMAGE
// Data           :     constant 0x4, Constant, Type: int, EF_MAGICAL_IGNORE_RESIST_STATE_DAMAGE
// Data           :     constant 0x6, Constant, Type: int, EF_PHYSICAL_IGNORE_DEFENCE_PER_STATE_DAMAGE
// Data           :     constant 0xB, Constant, Type: int, EF_HEAL_HP_BY_MAGIC
// Data           :     constant 0xC, Constant, Type: int, EF_HEAL_MP_BY_MAGIC
// Data           :     constant 0xD, Constant, Type: int, EF_HEAL_SP_BY_MAGIC
// Data           :     constant 0x15, Constant, Type: int, EF_HEAL_HP_BY_ITEM
// Data           :     constant 0x16, Constant, Type: int, EF_HEAL_MP_BY_ITEM
// Data           :     constant 0x17, Constant, Type: int, EF_HEAL_SP_BY_ITEM
// Data           :     constant 0x18, Constant, Type: int, EF_HEAL_HPMP_BY_ITEM
// Data           :     constant 0x19, Constant, Type: int, EF_HEAL_HPMP_PER_BY_ITEM
// Data           :     constant 0x33, Constant, Type: int, EF_POISON
// Data           :     constant 0x34, Constant, Type: int, EF_VENOM
// Data           :     constant 0x35, Constant, Type: int, EF_BLOODY
// Data           :     constant 0x36, Constant, Type: int, EF_SERIOUS_BLOODY
// Enum           :   <unnamed-tag>, Type: int
// Data           :     constant 0x0, Constant, Type: int, EF_MISC
// Data           :     constant 0x1, Constant, Type: int, EF_PARAMETER_INC
// Data           :     constant 0x2, Constant, Type: int, EF_PARAMETER_AMP
// Data           :     constant 0x3, Constant, Type: int, EF_PARAMETER_INC_WHEN_EQUIP_SHIELD
// Data           :     constant 0x4, Constant, Type: int, EF_PARAMETER_AMP_WHEN_EQUIP_SHIELD
// Data           :     constant 0x5, Constant, Type: int, EF_PARAMETER_INC_WHEN_EQUIP
// Data           :     constant 0x6, Constant, Type: int, EF_PARAMETER_AMP_WHEN_EQUIP
// Data           :     constant 0x15, Constant, Type: int, EF_DOUBLE_ATTACK
// Data           :     constant 0x16, Constant, Type: int, EF_ADDITIONAL_DAMAGE_ON_ATTACK
// Data           :     constant 0x17, Constant, Type: int, EF_AMP_ADDITIONAL_DAMAGE_ON_ATTACK
// Data           :     constant 0x18, Constant, Type: int, EF_ADDITIONAL_DAMAGE_ON_SKILL
// Data           :     constant 0x19, Constant, Type: int, EF_AMP_ADDTIONAL_DAMAGE_ON_SKILL
// Data           :     constant 0x1A, Constant, Type: int, EF_ADD_STATE_ON_ATTACK
// Data           :     constant 0x1B, Constant, Type: int, EF_ADD_HP_ON_ATTACK
// Data           :     constant 0x1E, Constant, Type: int, EF_AMP_RECEIVE_DAMAGE
// Data           :     constant 0x22, Constant, Type: int, EF_ADD_HP_MP_ON_CRITICAL
// Data           :     constant 0x23, Constant, Type: int, EF_HEALING_AMPLIFY
// Data           :     constant 0x28, Constant, Type: int, EF_STEAL_WITH_REGEN_STOP
// Data           :     constant 0x29, Constant, Type: int, EF_ABSORB
// Data           :     constant 0x2A, Constant, Type: int, EF_STEAL
// Data           :     constant 0x2B, Constant, Type: int, EF_DAMAGE_REFLECT_PERCENT
// Data           :     constant 0x2C, Constant, Type: int, EF_DAMAGE_REFLECT
// Data           :     constant 0x2D, Constant, Type: int, EF_DAMAGE_REFLECT_WHEN_EQUIP_SHIELD
// Data           :     constant 0x2E, Constant, Type: int, EF_DAMAGE_REDUCE_WITH_RACE_BY_PERCENT
// Data           :     constant 0x2F, Constant, Type: int, EF_DAMAGE_REDUCE_WITH_RACE_BY_VALUE
// Data           :     constant 0x31, Constant, Type: int, EF_MANA_SHIELD
// Data           :     constant 0x3D, Constant, Type: int, EF_HEAL
// Data           :     constant 0x3E, Constant, Type: int, EF_REGEN_ADD
// Data           :     constant 0x3F, Constant, Type: int, EF_HEAL_BY_ITEM
// Data           :     constant 0x40, Constant, Type: int, EF_HEAL_HPMP_PER
// Data           :     constant 0x47, Constant, Type: int, EF_FORCE_CHIP
// Data           :     constant 0x48, Constant, Type: int, EF_SOUL_CHIP
// Data           :     constant 0x49, Constant, Type: int, EF_HEALING_CHIP
// Data           :     constant 0x4A, Constant, Type: int, EF_LUNAR_CHIP
// Data           :     constant 0x51, Constant, Type: int, EF_NEUTRALIZE
// Data           :     constant 0x52, Constant, Type: int, EF_MEZZ
// Data           :     constant 0x53, Constant, Type: int, EF_PROVOKE
// Data           :     constant 0x54, Constant, Type: int, EF_DECREASE_STATE_EFFECT
// Data           :     constant 0x55, Constant, Type: int, EF_INC_HATE
// Data           :     constant 0x56, Constant, Type: int, EF_AMP_HATE
// Data           :     constant 0x57, Constant, Type: int, EF_SKILL_INTERRUPTION
// Data           :     constant 0x58, Constant, Type: int, EF_ADD_REGION_STATE
// Data           :     constant 0x5B, Constant, Type: int, EF_MP_COST_INC
// Data           :     constant 0x5C, Constant, Type: int, EF_ADD_PARAMETER_ON_NORMAL_ATTACK
// Data           :     constant 0x5D, Constant, Type: int, EF_ADD_PARAMETER_ON_SKILL
// Data           :     constant 0x5E, Constant, Type: int, EF_KNOCKBACK_ON_DEFAULT_ATTACK
// Data           :     constant 0x61, Constant, Type: int, EF_REMOVE_GOOD_STATE
// Data           :     constant 0x68, Constant, Type: int, EF_TRANSFORMATION
// Data           :     constant 0x69, Constant, Type: int, EF_DEAL_DAMAGE
// Data           :     constant 0x6A, Constant, Type: int, EF_AMPLIFY_CASTING_TIME
// Data           :     constant 0x6D, Constant, Type: int, EF_RESURRECTION
// Data           :     constant 0x6F, Constant, Type: int, EF_DETECT_HIDE
// Data           :     constant 0x70, Constant, Type: int, EF_CREATURE_PARAMETER_AMP
// Data           :     constant 0x71, Constant, Type: int, EF_GIVE_EXP_JP_TO_CREATURE
// Data           :     constant 0x72, Constant, Type: int, EF_CHANGING_FORM
// Data           :     constant 0xC8, Constant, Type: int, EF_RIDING
// Data           :     constant 0xC9, Constant, Type: int, EF_AMP_AND_INC_ITEM_CHANCE
// Enum           :   <unnamed-tag>, Type: int
// Data           :     constant 0x1, Constant, Type: int, FLAG_STR
// Data           :     constant 0x2, Constant, Type: int, FLAG_VIT
// Data           :     constant 0x4, Constant, Type: int, FLAG_AGI
// Data           :     constant 0x8, Constant, Type: int, FLAG_DEX
// Data           :     constant 0x10, Constant, Type: int, FLAG_INT
// Data           :     constant 0x20, Constant, Type: int, FLAG_MEN
// Data           :     constant 0x40, Constant, Type: int, FLAG_LUK
// Data           :     constant 0x80, Constant, Type: int, FLAG_ATTACK_POINT
// Data           :     constant 0x100, Constant, Type: int, FLAG_MAGIC_POINT
// Data           :     constant 0x200, Constant, Type: int, FLAG_DEFENCE
// Data           :     constant 0x400, Constant, Type: int, FLAG_MAGIC_DEFENCE
// Data           :     constant 0x800, Constant, Type: int, FLAG_ATTACK_SPEED
// Data           :     constant 0x1000, Constant, Type: int, FLAG_CAST_SPEED
// Data           :     constant 0x2000, Constant, Type: int, FLAG_MOVE_SPEED
// Data           :     constant 0x4000, Constant, Type: int, FLAG_ACCURACY
// Data           :     constant 0xFFFF8000, Constant, Type: int, FLAG_MAGIC_ACCURACY
// Data           :     constant 0x10000, Constant, Type: int, FLAG_CRITICAL
// Data           :     constant 0x20000, Constant, Type: int, FLAG_BLOCK
// Data           :     constant 0x40000, Constant, Type: int, FLAG_BLOCK_DEFENCE
// Data           :     constant 0x80000, Constant, Type: int, FLAG_AVOID
// Data           :     constant 0x100000, Constant, Type: int, FLAG_MAGIC_RESISTANCE
// Data           :     constant 0x200000, Constant, Type: int, FLAG_MAX_HP
// Data           :     constant 0x400000, Constant, Type: int, FLAG_MAX_MP
// Data           :     constant 0x800000, Constant, Type: int, FLAG_MAX_SP
// Data           :     constant 0x1000000, Constant, Type: int, FLAG_HP_REGEN_ADD
// Data           :     constant 0x2000000, Constant, Type: int, FLAG_MP_REGEN_ADD
// Data           :     constant 0x4000000, Constant, Type: int, FLAG_SP_REGEN_ADD
// Data           :     constant 0x8000000, Constant, Type: int, FLAG_HP_REGEN_RATIO
// Data           :     constant 0x10000000, Constant, Type: int, FLAG_MP_REGEN_RATIO
// Data           :     constant 0x40000000, Constant, Type: int, FLAG_MAX_WEIGHT
// Enum           :   <unnamed-tag>, Type: int
// Data           :     constant 0x1, Constant, Type: int, FLAG_ET_NONE_RESIST
// Data           :     constant 0x2, Constant, Type: int, FLAG_ET_FIRE_RESIST
// Data           :     constant 0x4, Constant, Type: int, FLAG_ET_WATER_RESIST
// Data           :     constant 0x8, Constant, Type: int, FLAG_ET_WIND_RESIST
// Data           :     constant 0x10, Constant, Type: int, FLAG_ET_EARTH_RESIST
// Data           :     constant 0x20, Constant, Type: int, FLAG_ET_LIGHT_RESIST
// Data           :     constant 0x40, Constant, Type: int, FLAG_ET_DARK_RESIST
// Data           :     constant 0x80, Constant, Type: int, FLAG_ET_NONE_INCREASE
// Data           :     constant 0x100, Constant, Type: int, FLAG_ET_FIRE_INCREASE
// Data           :     constant 0x200, Constant, Type: int, FLAG_ET_WATER_INCREASE
// Data           :     constant 0x400, Constant, Type: int, FLAG_ET_WIND_INCREASE
// Data           :     constant 0x800, Constant, Type: int, FLAG_ET_EARTH_INCREASE
// Data           :     constant 0x1000, Constant, Type: int, FLAG_ET_LIGHT_INCREASE
// Data           :     constant 0x2000, Constant, Type: int, FLAG_ET_DARK_INCREASE
// Data           :     constant 0x4000, Constant, Type: int, FLAG_ET_NONE_DAMAGE
// Data           :     constant 0xFFFF8000, Constant, Type: int, FLAG_ET_FIRE_DAMAGE
// Data           :     constant 0x10000, Constant, Type: int, FLAG_ET_WATER_DAMAGE
// Data           :     constant 0x20000, Constant, Type: int, FLAG_ET_WIND_DAMAGE
// Data           :     constant 0x40000, Constant, Type: int, FLAG_ET_EARTH_DAMAGE
// Data           :     constant 0x80000, Constant, Type: int, FLAG_ET_LIGHT_DAMAGE
// Data           :     constant 0x100000, Constant, Type: int, FLAG_ET_DARK_DAMAGE
// Data           :     constant 0x200000, Constant, Type: int, FLAG_ET_NONE_ADDITIONAL_DAMAGE
// Data           :     constant 0x400000, Constant, Type: int, FLAG_ET_FIRE_ADDITIONAL_DAMAGE
// Data           :     constant 0x800000, Constant, Type: int, FLAG_ET_WATER_ADDITIONAL_DAMAGE
// Data           :     constant 0x1000000, Constant, Type: int, FLAG_ET_WIND_ADDITIONAL_DAMAGE
// Data           :     constant 0x2000000, Constant, Type: int, FLAG_ET_EARTH_ADDITIONAL_DAMAGE
// Data           :     constant 0x4000000, Constant, Type: int, FLAG_ET_LIGHT_ADDITIONAL_DAMAGE
// Data           :     constant 0x8000000, Constant, Type: int, FLAG_ET_DARK_ADDITIONAL_DAMAGE
// Data           :     constant 0x10000000, Constant, Type: int, FLAG_CRITICAL_DAMAGE
// Data           :     constant 0x20000000, Constant, Type: int, FLAG_HP_REGEN_STOP
// Data           :     constant 0x40000000, Constant, Type: int, FLAG_MP_REGEN_STOP
// Enum           :   <unnamed-tag>, Type: int
// Data           :     constant 0x1, Constant, Type: int, FLAG_EQUIP_ONEHAND_SWORD
// Data           :     constant 0x2, Constant, Type: int, FLAG_EQUIP_TWOHAND_SWORD
// Data           :     constant 0x4, Constant, Type: int, FLAG_EQUIP_DAGGER
// Data           :     constant 0x8, Constant, Type: int, FLAG_EQUIP_TWOHAND_SPEAR
// Data           :     constant 0x10, Constant, Type: int, FLAG_EQUIP_TWOHAND_AXE
// Data           :     constant 0x20, Constant, Type: int, FLAG_EQUIP_ONEHAND_MACE
// Data           :     constant 0x40, Constant, Type: int, FLAG_EQUIP_TWOHAND_MACE
// Data           :     constant 0x80, Constant, Type: int, FLAG_EQUIP_HEAVY_BOW
// Data           :     constant 0x100, Constant, Type: int, FLAG_EQUIP_LIGHT_BOW
// Data           :     constant 0x200, Constant, Type: int, FLAG_EQUIP_CROSSBOW
// Data           :     constant 0x400, Constant, Type: int, FLAG_EQUIP_ONEHAND_STAFF
// Data           :     constant 0x800, Constant, Type: int, FLAG_EQUIP_TWOHAND_STAFF
// Data           :     constant 0x1000, Constant, Type: int, FLAG_EQUIP_DOUBLE_SWORD
// Data           :     constant 0x2000, Constant, Type: int, FLAG_EQUIP_DOUBLE_DAGGER
// Function       :   public void StructState::StructState(const struct StructState &)

        public State()
        {

        }

        public State(StateType type, StateCode code, int uid, uint caster, ushort level, uint start_time, uint end_time, int base_damage, bool bIsAura, int nStateValue, string szStateValue)
        {
            this.init(uid, (int)code);
            this.m_nCode = code;
            this.m_nLevel[2] = 0;
            this.m_nLevel[1] = 0;
            this.m_nLevel[0] = 0;
            this.m_hCaster[2] = 0;
            this.m_hCaster[1] = 0;
            this.m_hCaster[0] = 0;
            this.m_nStartTime[2] = 0;
            this.m_nStartTime[1] = 0;
            this.m_nStartTime[0] = 0;
            this.m_nEndTime[2] = 0;
            this.m_nEndTime[1] = 0;
            this.m_nEndTime[0] = 0;
            this.m_nRemainDuration[2] = 0;
            this.m_nRemainDuration[1] = 0;
            this.m_nRemainDuration[0] = 0;
            this.m_nLevel[(int)type] = level;
            this.m_hCaster[(int)type] = caster;
            this.m_nBaseDamage[(int)type] = base_damage;
            this.m_nStartTime[(int)type] = start_time;
            this.m_nEndTime[(int)type] = end_time;
            this.m_bAura = bIsAura;
            this.m_nLastProcessedTime = Globals.GetArTime();
            this.m_nTotalDamage = 0;
            this.m_nStateValue = nStateValue;
            this.m_szStateValue = szStateValue;
        }


// Function       :   public void StructState::~StructState()
// Function       :   public bool IsNeedDisplay()
// Function       :   public bool HasNormalType()
// Function       :   public bool HasDuplicateType()
// Function       :   public bool HasDependenceType()
// Function       :   public bool IsAura()

        public bool IsHolded()
        {
            uint v1;
            uint v2;

            v1 = this.m_nRemainDuration[0];
            v2 = this.m_nRemainDuration[1];
            if ( v1 <= v2 )
                v1 = v2;
            return v1 != 0;
        }
// Function       :   public void StructState::HoldRemainDuration()

        public void ReleaseRemainDuration()
        {

        }
// Function       :   public int GetStateValue()
// Function       :   public const char * GetStateStringValue()

        public bool AddState(StateType type, uint caster, ushort level, uint start_time, uint end_time, int base_damage, bool bIsAura)
        {
            bool result;

            if (this.m_nLevel[(int)type] <= level)
            {
                this.m_nLevel[(int)type] = level;
                this.m_nEndTime[(int)type] = end_time;
                this.m_nBaseDamage[(int)type] = base_damage;
                this.m_hCaster[(int)type] = caster;
                this.m_nStartTime[(int)type] = start_time;
                this.m_bAura = bIsAura;
                this.m_nLastProcessedTime = start_time;
                result = true;
            }
            else
            {
                result = false;
            }
            return result;
        }

// Function       :   public unsigned short GetUID()
// Function       :   public void SetUID(unsigned short)
// Function       :   public void SetLevel(int, unsigned short)
// Function       :   public void SetStartTime(int, unsigned long)
// Function       :   public void SetEndTime(int, unsigned long)
// Function       :   public void SetLastProcessedTime(unsigned long)
// Function       :   public unsigned short GetLevel(enum StructState::StateType)

        public ushort GetLevel()
        {
            ushort result = 0;
            if (this.m_nLevel[0] != 0 || this.m_nLevel[1] != 0)
                result = (ushort)(this.m_nLevel[0] + this.m_nLevel[1] + this.m_nLevel[2]);
            return result;

        }
// Function       :   public enum StructState::StateCode GetCode()
// Function       :   public unsigned long GetStartTime(int)
// Function       :   public unsigned long GetStartTime()
// Function       :   public unsigned long GetEndTime(int)
// Function       :   public unsigned long GetEndTime()
// Function       :   public unsigned long GetRemainDuration(int)
// Function       :   public unsigned long GetRemainDuration()
// Function       :   public unsigned long GetLastProcessedTime()
// Function       :   public unsigned int GetCaster(int)
// Function       :   public int GetBaseDamage(int)
// Function       :   public int GetBaseEffectID()
// Function       :   public unsigned long GetFireInterval()
// Function       :   public int GetElementalType()
// Function       :   public class c_fixed<10000> GetAmplifyBase()
// Function       :   public class c_fixed<10000> GetAmplifyPerSkillLevel()
// Function       :   public int GetAddDamageBase()
// Function       :   public int GetAddDamagePerSkillLevel()

        public int GetEffectType()
        {
            return this.m_info.effect_type;
        }

        public float GetValue(int idx)
        {
            return this.m_info.fValue[idx];
        }

        public bool IsHarmful()
        {
            return this.m_info.is_harmful != 0;
        }
// Function       :   public bool StructState::IsValid(unsigned long)
// Function       :   public bool StructState::ClearExpiredState(unsigned long)
// Function       :   public int StructState::GetStateGroup()

        public bool IsDuplicatedGroup(int nGroupID)
        {
            return this.m_info.duplicate_group[0] != 0 && this.m_info.duplicate_group[0] == nGroupID
                || this.m_info.duplicate_group[1] != 0 && this.m_info.duplicate_group[1] == nGroupID
                || this.m_info.duplicate_group[2] != 0 && this.m_info.duplicate_group[2] == nGroupID;

        }

        public void SetState(State.StateCode code, int uid, uint caster, ushort[] levels, uint[] durations, int[] remain_times, uint last_fire_time, int[] base_damage, int state_value, string szStateValue)
        {
            uint t;
            int i;

            this.init(uid, (int)code);
            this.m_nCode = code;
            i = 0;
            t = Globals.GetArTime();
//             durationsa = this.m_nLevel;
//             v13 = caster - base_damage;
//             uida = (base_damage - v12);
//             v14 = this.m_nEndTime;
//             base_damagea = caster - base_damage;
//             castera = (remain_times - v12);
// 
//         public int[] m_nLevel = new int[3];                                                 // 0xC
//         public int[] m_nBaseDamage = new int[3];                                            // 0x14
//         public uint[] m_hCaster = new uint[3];                                              // 0x20
//         public uint[] m_nStartTime = new uint[3];                                           // 0x2C
//         public uint[] m_nEndTime = new uint[3];                                             // 0x38
//         public uint[] m_nRemainDuration = new uint[3];                                      // 0x44

            for(i = 0; i < 3; ++i)
            {
                this.m_nLevel[i] = levels[i];
                this.m_hCaster[i] = caster;
                this.m_nBaseDamage[i] = base_damage[i];

                if(durations[i] != 0)
                {
                    uint v;
                    if ( t <= durations[i] - remain_times[i])
                        v = 0;
                    else
                        v = (uint)(t + (uint)remain_times[i] - durations[i]);
                    this.m_nStartTime[i] = v;

                    this.m_nEndTime[i] = (uint) remain_times[i];
                    if (this.m_nEndTime[i] != 0xffffffff)
                        this.m_nEndTime[i] += t;
                }
                else
                {
                    this.m_nEndTime[i] = 0;
                    this.m_nStartTime[i] = 0;
                }


//                this.m_nRemainDuration[i] = durations[i];
            }
            this.m_nLastProcessedTime = last_fire_time;
            this.m_nStateValue = state_value;
            this.m_szStateValue = szStateValue;
        }

        public int GetTimeType()
        {
            return this.m_info.state_time_type;
        }
// Function       :   public void AddTotalDamage(int)
// Function       :   public int GetTotalDamage()
// Function       :   public const bool IsLogRequiredOnExpiration()
// Function       :   public const bool IsByEvent()


        protected void init(int uid, int code)
        {
            this.m_info = GameContent.GetStateInfo(code);
            this.m_nUID = (ushort)uid;
        }


        public ushort m_nUID;                                                               // 0x4
        public StateCode m_nCode;                                                           // 0x8
        public int[] m_nLevel = new int[3];                                                 // 0xC
        public int[] m_nBaseDamage = new int[3];                                            // 0x14
        public uint[] m_hCaster = new uint[3];                                              // 0x20
        public uint[] m_nStartTime = new uint[3];                                           // 0x2C
        public uint[] m_nEndTime = new uint[3];                                             // 0x38
        public uint[] m_nRemainDuration = new uint[3];                                      // 0x44
        public uint m_nLastProcessedTime;                                                   // 0x50
        public StateInfo m_info = new StateInfo();                                          // 0x54
        public int m_nTotalDamage;                                                          // 0x58
        public bool m_bAura;                                                                // 0x5C
        public int m_nStateValue;                                                           // 0x60
        public string m_szStateValue;                                                       // 0x64
        public bool m_bByEvent;                                                             // 0x65, Member, Type: bool, 

    }
}
